package io.renren.uitls;

import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author: xiaomi
 * @date: 2022/2/11
 * @description:
 */
public class BizSome {

    public static void main(String[] args) {
//        splitString();
        match();
        match2();
    }


    public static void splitString() {
        String str = "keyxxxxkeyxxkey";
        str = "keyx1keykeyx2key";
        String[] keys = str.split("key");
        Arrays.stream(keys).forEach(p -> System.out.println(p));
    }

    public static void match() {
        String nginxStr = "通过揉和众多设计良好的 Nginx 模块有效地把 Nginx";
        String regex = "[nN][gG]";
        boolean matches = Pattern.matches(regex, nginxStr);
        System.out.println("matches = " + matches);
    }

    /**
     * NOTEME ! 惊天大发现！居然与上面的不一样！
     */
    public static void match2(){
        String nginxStr = "通过揉和众多设计良好的 Nginx 模块有效地把 Nginx";
        String regex = "[nN][gG]";
        Pattern compile = Pattern.compile(regex);
        Matcher matcher = compile.matcher(nginxStr);
        System.out.println(matcher.find());
    }

    public static void split(){
        String nginxStr = "通过揉和众多设计良好的 Nginx 模块有效地把 Nginx";
        String regex = "[nN][gG]";
        String[] splits= nginxStr.split(regex);
        Arrays.stream(splits).forEach(p -> System.out.println(p));
    }
}
